"use strict";
cc._RF.push(module, '3ed843BOSpJJ4bgB+65qB6T', 'Menu');
// scripts/Menu.ts

Object.defineProperty(exports, "__esModule", { value: true });
var Model_1 = require("./Model");
var Config_1 = require("./Config");
var WxUtil_1 = require("./WxUtil");
var wx = window['wx'];
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Menu = /** @class */ (function (_super) {
    __extends(Menu, _super);
    function Menu() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.draw_label = null;
        _this.draw_Complete = null;
        _this.drop_label = null;
        _this.drop_Complete = null;
        _this.drag_label = null;
        _this.drag_Complete = null;
        _this.prcise_label = null;
        _this.price_Complete = null;
        // LIFE-CYCLE CALLBACKS:
        _this.wxSubContextView = null;
        _this.bg = null;
        return _this;
    }
    Menu_1 = Menu;
    Menu.prototype.onLoad = function () {
        Config_1.default.init();
        this.draw_label.getComponent(cc.Label).string = (Model_1.default.game.drawLevel - 1) + '/' + (Config_1.default.drawLevels.length - 1);
        this.drop_label.getComponent(cc.Label).string = (Model_1.default.game.dropLevel - 1) + '/' + (Config_1.default.brickLevels.length - 1);
        this.drag_label.getComponent(cc.Label).string = (Model_1.default.game.dragLevel - 1) + '/' + (Config_1.default.dragLevels.length - 1);
        this.prcise_label.getComponent(cc.Label).string = (Model_1.default.game.preciseLevel - 1) + '/' + (Config_1.default.preciseLevels.length - 1);
        this.price_Complete.active = Model_1.default.game.completeInfo[0] == 1;
        this.drop_Complete.active = Model_1.default.game.completeInfo[1] == 1;
        this.drag_Complete.active = Model_1.default.game.completeInfo[2] == 1;
        this.draw_Complete.active = Model_1.default.game.completeInfo[3] == 1;
        if (!cc.audioEngine.isMusicPlaying())
            cc.audioEngine.playMusic(this.bg, true);
        WxUtil_1.default.showShareMenu();
        WxUtil_1.default.showBanner();
    };
    Menu.prototype.onLevelUIClick = function (e) {
        Model_1.default.game.selectedModel = 4;
        cc.director.loadScene('levelUI');
    };
    Menu.prototype.onPreciseClick = function (e) {
        Model_1.default.game.selectedModel = 1;
        if (Model_1.default.game.preciseLevel > Config_1.default.preciseLevels.length - 1) {
            Model_1.default.game.preciseLevel = 1;
        }
        Model_1.default.game.selectedLevel = Model_1.default.game.preciseLevel;
        cc.director.loadScene('game');
    };
    Menu.prototype.onDropClick = function (e) {
        Model_1.default.game.selectedModel = 2;
        if (Model_1.default.game.dropLevel > Config_1.default.brickLevels.length - 1) {
            Model_1.default.game.dropLevel = 1;
        }
        Model_1.default.game.selectedLevel = Model_1.default.game.dropLevel;
        cc.director.loadScene('gameDrop');
    };
    Menu.prototype.onDragClick = function (e) {
        if (Model_1.default.game.dragLevel > Config_1.default.dragLevels.length - 1) {
            Model_1.default.game.dragLevel = 1;
        }
        Model_1.default.game.selectedModel = 3;
        Model_1.default.game.selectedLevel = Model_1.default.game.dragLevel;
        cc.director.loadScene('gameDrag');
    };
    Menu.prototype.onDrawClick = function (e) {
        Model_1.default.game.selectedModel = 4;
        if (Model_1.default.game.drawLevel <= Config_1.default.drawLevels.length - 1) {
            Model_1.default.game.selectedLevel = Model_1.default.game.drawLevel;
            cc.director.loadScene('gameDraw');
        }
        else {
            cc.director.loadScene('levelUI');
        }
    };
    Menu.prototype.onRankClick = function (e) {
        if (typeof wx === 'undefined') {
            return;
        }
        this.initUserInfoButton();
        if (!this.wxSubContextView.active) {
            // 设置容器可见
            this.wxSubContextView.active = true;
            // 发送结算分数到开放域
            wx.getOpenDataContext().postMessage({
                message: 'show'
            });
            console.log('显示排行榜');
        }
        else {
            // 设置容器不可见，即关闭排行榜，并让开放域清空排名信息
            this.wxSubContextView.active = false;
            wx.getOpenDataContext().postMessage({
                message: 'clear'
            });
            console.log('关闭排行榜');
        }
    };
    Menu.prototype.initUserInfoButton = function () {
        // 微信授权，此代码来自Cocos官方
        if (typeof wx === 'undefined') {
            return;
        }
        if (Menu_1.hasCreatAuthorBtn) {
            return;
        }
        var systemInfo = wx.getSystemInfoSync();
        var width = systemInfo.windowWidth;
        var height = systemInfo.windowHeight;
        var button = wx.createUserInfoButton({
            type: 'text',
            text: '',
            style: {
                left: 0,
                top: 0,
                width: width,
                height: height,
                lineHeight: 40,
                backgroundColor: '#00000000',
                color: '#00000000',
                textAlign: 'center',
                fontSize: 10,
                borderRadius: 4
            }
        });
        if (Menu_1.hasCreatAuthorBtn == false) {
            Menu_1.hasCreatAuthorBtn = true;
        }
        button.onTap(function (res) {
            if (res.userInfo) {
                // 可以在这里获取当前玩家的个人信息，如头像、微信名等。
                console.log('授权成功！');
            }
            else {
                console.log('授权失败！');
            }
            button.hide();
            button.destroy();
        });
    };
    Menu.prototype.onShareClick = function (e) {
        WxUtil_1.default.share();
    };
    Menu.prototype.onCloseRank = function (e) {
        this.wxSubContextView.active = false;
        wx.getOpenDataContext().postMessage({
            message: 'clear'
        });
        console.log('关闭排行榜');
    };
    Menu.prototype.onFeedBackClick = function (e) {
    };
    Menu.prototype.onDestroy = function () {
        console.log('销毁menu');
        WxUtil_1.default.destroyBanner();
    };
    var Menu_1;
    Menu.hasCreatAuthorBtn = false;
    __decorate([
        property(cc.Label)
    ], Menu.prototype, "draw_label", void 0);
    __decorate([
        property(cc.Node)
    ], Menu.prototype, "draw_Complete", void 0);
    __decorate([
        property(cc.Label)
    ], Menu.prototype, "drop_label", void 0);
    __decorate([
        property(cc.Node)
    ], Menu.prototype, "drop_Complete", void 0);
    __decorate([
        property(cc.Label)
    ], Menu.prototype, "drag_label", void 0);
    __decorate([
        property(cc.Node)
    ], Menu.prototype, "drag_Complete", void 0);
    __decorate([
        property(cc.Label)
    ], Menu.prototype, "prcise_label", void 0);
    __decorate([
        property(cc.Node)
    ], Menu.prototype, "price_Complete", void 0);
    __decorate([
        property(cc.Node)
    ], Menu.prototype, "wxSubContextView", void 0);
    __decorate([
        property({ type: cc.AudioClip })
    ], Menu.prototype, "bg", void 0);
    Menu = Menu_1 = __decorate([
        ccclass
    ], Menu);
    return Menu;
}(cc.Component));
exports.default = Menu;

cc._RF.pop();